package com.hd.crdao.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hd.crdao.R;
import com.hd.crdao.base.BaseSecondActivity;
import com.hd.crdao.bean.GetStoreAuthstatusBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.ALog;
import com.hd.crdao.utils.MyToast;
import com.hd.crdao.utils.SPUtils;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.view.ExpandHeadView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import okhttp3.Call;

/**
 *
 *@author Programming
 *@date 2017/6/26 0026
 */
public class OpenShopCertificationActivity extends BaseSecondActivity {
    @BindView(R.id.openshopcertificatino_head)
    ExpandHeadView mOpenshopcertificatinoHead;
    @BindView(R.id.name)
    TextView mName;
    @BindView(R.id.phonenumber)
    TextView mPhonenumber;
    @BindView(R.id.certificationState)
    TextView mCertificationState;
    @BindView(R.id.operation)
    Button mOperation;
    @BindView(R.id.backreason)
    TextView mBackreason;
    @BindView(R.id.rejectarea)
    LinearLayout mRejectarea;
    public int storeAuthstatus;
    private String detailAddress;

    @Override
    protected int setContentView() {
        return R.layout.activity_openshopcertification;
    }

    @Override
    protected ExpandHeadView setExpandHeadView() {
        return mOpenshopcertificatinoHead;
    }

    @Override
    protected void initView() {
        initData();
        mOperation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String operationName = mOperation.getText().toString();

                if (TextUtils.equals(operationName, "创建店铺")) {
                    Intent intent = new Intent(UIUtils.getContext(), CreateShopActivity.class);
                    intent.putExtra("create", "create");//如果是创建店铺就不会回显信息
                    startActivity(intent);
                } else if (TextUtils.equals(operationName, "进入我的店铺")) {
                    startActivity(new Intent(UIUtils.getContext(), MyShopActivity.class));
                } else {
                    if (storeAuthstatus == 2) {
                        finish();
                    }
                    Intent intent = new Intent(UIUtils.getContext(), IdCertificationActivity.class);
                    intent.putExtra("certstate", storeAuthstatus);
                    ALog.d(storeAuthstatus + "");
                    startActivity(intent); //去认证进入身份认证
                }

            }
        });
    }

    private void initData() {
        OkHttpUtils.post().url(Constants.GETSTOREAUTHSTATUS_URL)
                .addParams("sign", Constants.SIGN)
                .addParams("carBusinessId", SPUtils.getString("businessid", ""))
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                MyToast.show("服务器连接失败");
            }

            @Override
            public void onResponse(String response, int id) {
                ALog.d(response);
                GetStoreAuthstatusBean storeAuthstatusBean = new Gson().fromJson(response, GetStoreAuthstatusBean.class);
                storeAuthstatus = storeAuthstatusBean.getCarBusiness().getStoreAuthstatus();
                String[] openShopStatus = getResources().getStringArray(R.array.openshopstatus);
                String[] buttonContent = getResources().getStringArray(R.array.openshopstatus_button);
                if (storeAuthstatus == 2) {
                    mRejectarea.setVisibility(View.VISIBLE);
                    mBackreason.setText(storeAuthstatusBean.getCarBusiness().getStoreReject());
                } else {
                    mRejectarea.setVisibility(View.GONE);
                }
                mName.setText(storeAuthstatusBean.getCarBusiness().getCbContacts());
                mPhonenumber.setText(storeAuthstatusBean.getCarBusiness().getCbContphone());
                mCertificationState.setText(openShopStatus[storeAuthstatus]);
                mOperation.setText(buttonContent[storeAuthstatus]);

            }
        });
    }


}
